// 数据转换压缩
export const dataCompress = (data, callbackFn = null) => {
  if (!(data instanceof Array)) {
    return data
  }
  let header = []
  const body = []
  let i = 0
  for (let item of data) {
    if (!(item instanceof Object)) {
      return data
    }
    if (callbackFn instanceof Function) {
      item = callbackFn({
        ...item
      })
    }
    const cKey = Object.keys(item)
    const cData = Object.values(item)
    if (i > 0 && cKey.join('|') !== header.join('|')) {
      return data
    }
    header = cKey
    body.push(cData)
    i++;
  }
  return {
    header,
    body
  }
}
// 数据还原
export const dataUnCompress = (data) => {
  let header = data.header
  let body = data.body
  const newArray = []
  for (let item of body) {
    let temp = {}
    for (let key in header) {
      temp[header[key]] = item[key]
    }
    newArray.push(temp)
  }
  return newArray
}